﻿using System;
using System.Windows;
using System.Windows.Interactivity;
using Orktane.Components;

namespace Orktane.Behaviors
{
    public class ScriptActionConsoleBehavior 
        : Behavior<FrameworkElement>
    {
        private const string MUSTBE_ICONSOLEHOST =
            "ScriptActionConsoleBehavior must be attached to an IConsoleHost implementing control.";

        private ScriptActionConsoleExtenstion _consoleExtension;

#region Overrides

        protected override void OnAttached()
        {
            var _host = (IConsoleHost)this.AssociatedObject;
            if (_host == null) throw new InvalidOperationException(MUSTBE_ICONSOLEHOST);
            _consoleExtension = new ScriptActionConsoleExtenstion(_host.Console);
        }

        protected override void OnDetaching()
        {
            _consoleExtension.Console.Dispose();
            _consoleExtension = null;
        }

#endregion

    }
}
